<template>
	<view class="container">
		<image class="header-bg" v-if="resource['headbar_bg']" :src="resource['headbar_bg'].fileUrl" mode="widthFix"></image>
		<view class="body">
			<view class="custom-title-bar">
				<view class="icon" @click="back"><uni-icons type="left" size="24" color="#333333"></uni-icons></view>
				<view class="text">补贴查询</view>
				<view class="right"></view>
			</view>
			<view class="summation">
				<image class="icon" src="@/static/img/icons/heart.png" mode="widthFix"></image>
				<view class="text">
					<view class="label"><text style="margin-right: 10upx;">{{user.name}}</text><text class="sub-label">{{user.yearFrom?user.yearFrom:'?'}}-{{user.yearTo?user.yearTo:year}}</text></view>
					<view class="value">{{(stat.total||stat.total==0)?stat.total:'--'}}<text class="unit">元</text></view>
				</view>
			</view>
			<view class="list">
				<view class="cell-box" v-if="!hasCurrentYear">
					<view class="current">
						<image class="icon" src="@/static/img/icons/question.png" mode="widthFix"></image>
						<view class="title">今年暂无补贴发放数据</view>
					</view>
				</view>
				<view class="cell-box" v-for="item in list">
					<view class="left">
						<view class="text-wrap">
							<view class="text">{{item.year}}年</view>
							<view class="text">【{{item.period}}】</view>
						</view>
						<view class="label">{{item.programName?item.programName:''}}</view>
						<view class="label" v-if="item.disbursementStatus=='1'">{{item.disbursementDate?item.disbursementDate:''}}<text class="emphasize">已发放</text></view>
						<view class="label" v-else>{{item.disbursementStatus?'未发放':''}}</view>
					</view>
					<view class="right">
						<view class="icon">
							<image class="icon" :src="'../../../static/img/icons/'+(item.disbursementStatus=='1'?'ok.png':'question.png')" mode="widthFix"></image>
						</view>
						<view class="text">{{item.disbursementMoney?item.disbursementMoney:''}}元</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import Store from '@/store/index.js';
	// import { ApiDisbursement } from "@/api/subsidy/index.js";
	import { ApiIdentifySchedulePerson } from "@/api/identify/index.js";
	import { ApiResource } from '@/api/application/index.js';
	import moment from "moment";
	import 'moment/locale/zh-cn';
	
	export default {
		data() {
			return {
				resource: {},
				user:{},
				list: [],
				year: '',
				stat: {
					total: undefined
				},
				hasCurrentYear: false
			}
		},
		created() {
			moment.locale('zh-cn');
			this.year = moment().year();
			this.getResources();
		},
		onLoad(option) {
			if(option.idNumber){
				this.user = {
					id: option.id,
					name: option.name,
					idNumber: option.idNumber,
					yearFrom: option.yearFrom?option.yearFrom:'',
					yearTo: option.yearTo?option.yearTo:''
				}
			} else {
				this.user = Store.getUser();
			}
			this.getList();
			this.getStat();
		},
		methods: {
			//获取网络资源
			getResources(){
				ApiResource.getByCode('headbar_bg').then(res=>{
					this.resource = {
						'headbar_bg': res.data
					};
				})
			},
			
			getList(){
				ApiIdentifySchedulePerson.list({
					idNumber: this.user.idNumber,
					// checkStatus: '1',				//年审审核通过
					status: '1'
				}).then(res=>{
					console.log(1234)
					console.log(res)
					this.list = res.data;
					this.currentYear();
				})
			},
			
			getStat(){
				ApiIdentifySchedulePerson.disbursementStat({
					idNumber: this.user.idNumber,
					disbursementStatus:'1',
					status: '1'
				}).then(res=>{
					this.stat = res.data;
				})
			},
			
			//今年数据：
			currentYear(){
				let year = moment().year();
				let has = false;
				this.list.forEach(item=>{
					if(item.year === year){
						has = true;
					}
				})
				this.hasCurrentYear = has;
			},
			
			back(){
				uni.navigateBack();
			},
			
		}
	}
</script>

<style>
	.container {
		width: 750upx;
		height: 100vh;
		position: relative;		
	}
	.header-bg{
		width: 750upx;
		position: absolute;
		left: 0;
		right: 0;
		top: 0;
	}
	.body{
		width: 100vw;
		/* height: 100vh; */
		position: absolute;
		top: 0upx;
	}
	.summation{
		width: 750upx;
		padding: 40upx 80upx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
	.summation .icon{
		width: 160upx;
	}
	.summation .text{
		display: flex;
		flex-direction: column;
		align-items: flex-end;
	}
	.summation .text .label{
		font-size: 18px;
		font-weight: bold;
	}
	.summation .text .label .sub-label{
		font-size: 12px;
		color: #666666;
		margin-right: 5upx;
	}
	.summation .text .value{
		font-size: 24px;
		font-weight: bold;
		color: #FF6A00;
	}
	.summation .text .unit{
		font-size: 18px;
		font-weight: bold;
		color: #FF6A00;
		margin-left: 5upx;
	}
	.list{
		width: 750upx;
		padding: 30upx;
		padding-top: 0upx;
		box-sizing: border-box;
	}
	.list .cell-box{
		background-color: white;
		border-radius: 5upx;
		padding: 40upx;
		display: flex;
		margin-bottom: 30upx;
		align-items: center;
		justify-content: space-between;
	}
	.list .cell-box .left{

	}
	.list .cell-box .left .text-wrap{
		display: flex;
		align-items: center;
	}
	.list .cell-box .left .label{
		margin-top: 10upx;
		font-size: 14px;
		color: #666666;
	}
	.list .cell-box .left .text{
		font-size: 18px;
		font-weight: bold;
		margin-right: 10upx;
	}
	.list .cell-box .left .sub-text{
		font-size: 12px;
		color: #666666;
	}
	.list .cell-box .right{
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		flex-wrap: nowrap;
	}
	.list .cell-box .right .icon{
		width: 80upx;
		height: 80upx;
	}
	.list .cell-box .right .text{
		font-size: 18px;
		font-weight: bold;
		color: #FF6A00;
		flex-wrap: nowrap;
		margin-top: 10upx;
	}
	.list .cell-box .current {
		width: 100%;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}
	.list .cell-box .current .title {
		font-size: 14px;
		font-weight: bold;
		text-align: center;
		margin-top: 10upx;
	}
	.list .cell-box .current .icon {
		width: 50upx;
		height: 50upx;
	}
	.emphasize{
		color: #FF6A00;
	}
	
</style>
